#include "studybrowser.h"
#include "ui_studybrowser.h"
#include "../../ImageAcquisitor/ImageAcquisitor/global.h"
#include "studytablemodel.h"
#include "findstudywidget.h"

StudyBrowser::StudyBrowser(QWidget *parent) :
    studyModel(0),
    QWidget(parent),
    ui(new Ui::StudyBrowser)
{
    ui->setupUi(this);
    initUi();
}

StudyBrowser::~StudyBrowser()
{
    delete ui;
}

void StudyBrowser::initUi()
{
    studyModel = new StudyTableModel(this, QSqlDatabase::database());
    ui->studyView->setModel(studyModel);
    QDateTime t;
    t.setDate(QDate::currentDate());
    t.setTime(QTime::fromString("00:00:00", "hh:mm:ss"));
    studyModel->setFromTime(t);
    t.setTime(QTime::fromString("23:59:59", "hh:mm:ss"));
    studyModel->setToTime(t);
    studyModel->applyFilter();
    studyModel->select();

    connect(ui->findStudy, SIGNAL(findStudy()), this, SLOT(onFindStudy()));
}

void StudyBrowser::onFindStudy()
{
    studyModel->setFromTime(ui->findStudy->getFromTime());
    studyModel->setToTime(ui->findStudy->getToTime());
    studyModel->setModality(ui->findStudy->getModality());
    studyModel->setPatientId(ui->findStudy->getPatientId());
    studyModel->setPatientName(ui->findStudy->getPatientName());
    studyModel->setAccNum(ui->findStudy->getAccNum());
    studyModel->applyFilter();
}
